import {
	app,
	BrowserWindow,
	Menu,
	Tray,
	nativeImage
} from 'electron';

import path from 'node:path';

let mainWindow:BrowserWindow
const contextMenu = Menu.buildFromTemplate([
    { label: '显示窗口', click:()=>{mainWindow.show()}},
    { label: '退出应用', click:()=>{global.isClose=true;app.quit()} }
])

function creatTray(w:BrowserWindow){
    mainWindow=w;
    const icon = nativeImage.createFromPath(path.join(__dirname, 'static','icon.ico'))
    const tray = new Tray(icon)

    tray.setContextMenu(contextMenu)
	tray.setToolTip('vite-electron-vue')
	tray.setTitle('vite-electron-vue')

	tray.on('double-click', () => {
		mainWindow.show()
	})

    return tray
}

export default creatTray